/*
 * Copyright 2022 The Open Islands Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.openislands.oi.rpc.base;

import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Objects;

@SuppressWarnings("unused")
public class RouteNode implements Iterable<RouteNode> {
    private String httpAccess;
    private String httpsAccess;
    private String grpcAccess;
    private String grpcsAccess;
    private Boolean tlsEnabled;
    private RouteNode nextNode;

    public String getHttpAccess() {
        return httpAccess;
    }

    public void setHttpAccess(String httpAccess) {
        this.httpAccess = httpAccess;
    }

    public String getHttpsAccess() {
        return httpsAccess;
    }

    public void setHttpsAccess(String httpsAccess) {
        this.httpsAccess = httpsAccess;
    }

    public String getGrpcAccess() {
        return grpcAccess;
    }

    public void setGrpcAccess(String grpcAccess) {
        this.grpcAccess = grpcAccess;
    }

    public String getGrpcsAccess() {
        return grpcsAccess;
    }

    public void setGrpcsAccess(String grpcsAccess) {
        this.grpcsAccess = grpcsAccess;
    }

    public Boolean getTlsEnabled() {
        return tlsEnabled;
    }

    public void setTlsEnabled(Boolean tlsEnabled) {
        this.tlsEnabled = tlsEnabled;
    }

    public RouteNode getNextNode() {
        return nextNode;
    }

    public void setNextNode(RouteNode nextNode) {
        this.nextNode = nextNode;
    }

    @Override
    public Iterator<RouteNode> iterator() {
        return new RouteNodeIterator(this);
    }

    public static class RouteNodeIterator implements Iterator<RouteNode> {
        private RouteNode routeNode;

        public RouteNodeIterator(RouteNode routeNode) {
            this.routeNode = routeNode;
        }

        @Override
        public boolean hasNext() {
            return routeNode != null;
        }

        @Override
        public RouteNode next() throws NoSuchElementException {
            if (Objects.isNull(this.routeNode)) throw new NoSuchElementException("null routeNode");
            RouteNode temp = this.routeNode;
            this.routeNode = temp.getNextNode();
            return temp;
        }
    }
}
